﻿using System;
using System.Collections.Generic;
using System.Web;
using WAD.WEB.AppCode;
using WAD.DAL;
using WAD.Model;

namespace WAD.WEB.Admin.Ajax
{

    public class UserVersion : AdminAjax 
    {
        public override void AjaxMethodDispatch(String identity)
        {
            switch (identity)
            {
                case "getbyuserid": this.GetByUserId(); break;
                case "add": this.Add(); break;
                case "getpalist": this.GetPalist(); break;
                case "cancenl": this.Cancenl(); break;
            }
        }
        [QD.Web.Ajax.AjaxMethod]
        public void GetByUserId()
        {
            int id = Parse.Int("id", 0);
            //success(DAOUserVersion.GetByUserId(id));
        }

        //添加套餐
        [QD.Web.Ajax.AjaxMethod]
        public void Add()
        {
            int userid = Parse.Int("userid",0);
            int version = Parse.Int("version",0);
            DateTime data = (DateTime)Parse.Date("data");
            DateTime enddata = (DateTime)Parse.Date("endata");
            
           MUserVersion mver = new MUserVersion(){user_id=userid, version_id=version, date=data,end_date=enddata};

           //if (DAL.DaoUserVersion.GetEntity(userid,version) != null)
           //{
           //    if (DAL.DaoUserVersion.Updatecharge(mver))
           //    {
           //        Success();
           //    }
           //    else
           //    {
           //        Fail();
           //    }
           //}
           //else
           //{
               if (DAL.DaoUserVersion.Add(mver))
               {
                   Success();
               }
               else
               {
                   Fail();
               }
          // }
        }

        //获取套餐列表
          [QD.Web.Ajax.AjaxMethod]
          public void GetPalist()
          {
              int id = Parse.Int("userid", 0);
              int pageindex = Parse.Int("pageindex", 0);

              Success(DAL.DaoUserVersion.GetpaList(pageindex,10,id));
          }

        //取消套餐
          [QD.Web.Ajax.AjaxMethod]
          public void Cancenl()
          {
              int id = Parse.Int("id", 0);
              int userid = Parse.Int("userid", 0);
              
              Success(DAL.DaoUserVersion.Hide(id,userid));
          }

    }
}